package org.example.work.controller;

import lombok.RequiredArgsConstructor;
import org.example.work.dox.User;
import org.example.work.service.UserService;
import org.example.work.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/admin/")
@RequiredArgsConstructor
public class AdminController {
    private final UserService userService;
    //添加user
    @PostMapping("user")
    public ResultVO postUser(@RequestBody User user) {
        userService.addUser(user);
        return ResultVO.ok();
    }
    //重置密码
    @PutMapping("users/{account}/password")
    public ResultVO putPassword(@PathVariable String account) {
        userService.updateUserPassword(account);
        return ResultVO.ok();
    }
    //查看user
    @GetMapping("users")
    public ResultVO listUsers(){
        return ResultVO.success(userService.listUsers());
    }
}
